home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / gridex / frmorder.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-01-02  |  33.1 KB  |  974 lines

  1. VERSION 5.00
  2. Object = "{BA7155BB-813E-11D1-B8F4-0080ADA85B53}#1.0#0"; "JSGridEX.ocx"
  3. Begin VB.Form frmOrders 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Orders"
  6.    ClientHeight    =   5460
  7.    ClientLeft      =   525
  8.    ClientTop       =   1965
  9.    ClientWidth     =   8040
  10.    BeginProperty Font 
  11.       Name            =   "Tahoma"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   400
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "frmOrders.frx":0000
  20.    LinkTopic       =   "Form1"
  21.    LockControls    =   -1  'True
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    ScaleHeight     =   5460
  25.    ScaleWidth      =   8040
  26.    StartUpPosition =   2  'CenterScreen
  27.    Begin VB.CommandButton cmdOK 
  28.       Caption         =   "OK"
  29.       Default         =   -1  'True
  30.       Height          =   360
  31.       Left            =   3015
  32.       TabIndex        =   8
  33.       Top             =   5040
  34.       Width           =   1200
  35.    End
  36.    Begin VB.CommandButton cmdCancel 
  37.       Cancel          =   -1  'True
  38.       Caption         =   "Cancel"
  39.       Height          =   360
  40.       Left            =   4335
  41.       TabIndex        =   9
  42.       Top             =   5040
  43.       Width           =   1200
  44.    End
  45.    Begin VB.ComboBox cboShippers 
  46.       Height          =   315
  47.       Left            =   5310
  48.       Style           =   2  'Dropdown List
  49.       TabIndex        =   3
  50.       Top             =   1920
  51.       Width           =   2655
  52.    End
  53.    Begin VB.ComboBox cboEmployee 
  54.       Height          =   315
  55.       Left            =   1200
  56.       Sorted          =   -1  'True
  57.       Style           =   2  'Dropdown List
  58.       TabIndex        =   2
  59.       Top             =   1920
  60.       Width           =   2805
  61.    End
  62.    Begin VB.PictureBox Picture2 
  63.       Height          =   1395
  64.       Index           =   0
  65.       Left            =   4065
  66.       ScaleHeight     =   89
  67.       ScaleMode       =   3  'Pixel
  68.       ScaleWidth      =   256
  69.       TabIndex        =   28
  70.       Top             =   465
  71.       Width           =   3900
  72.       Begin VB.TextBox txtShip 
  73.          BorderStyle     =   0  'None
  74.          Height          =   240
  75.          Index           =   3
  76.          Left            =   1785
  77.          TabIndex        =   34
  78.          Top             =   765
  79.          Width           =   975
  80.       End
  81.       Begin VB.TextBox txtShip 
  82.          BorderStyle     =   0  'None
  83.          Height          =   240
  84.          Index           =   2
  85.          Left            =   765
  86.          TabIndex        =   33
  87.          Top             =   765
  88.          Width           =   975
  89.       End
  90.       Begin VB.TextBox txtShip 
  91.          BorderStyle     =   0  'None
  92.          Height          =   240
  93.          Index           =   5
  94.          Left            =   1635
  95.          TabIndex        =   32
  96.          Top             =   1050
  97.          Width           =   2130
  98.       End
  99.       Begin VB.TextBox txtShip 
  100.          BorderStyle     =   0  'None
  101.          Height          =   240
  102.          Index           =   4
  103.          Left            =   2790
  104.          TabIndex        =   31
  105.          Top             =   765
  106.          Width           =   975
  107.       End
  108.       Begin VB.TextBox txtShip 
  109.          BorderStyle     =   0  'None
  110.          Height          =   405
  111.          Index           =   1
  112.          Left            =   765
  113.          MultiLine       =   -1  'True
  114.          TabIndex        =   30
  115.          Top             =   315
  116.          Width           =   3000
  117.       End
  118.       Begin VB.TextBox txtShip 
  119.          BorderStyle     =   0  'None
  120.          Height          =   240
  121.          Index           =   0
  122.          Left            =   765
  123.          TabIndex        =   29
  124.          Top             =   30
  125.          Width           =   3000
  126.       End
  127.       Begin VB.Label Label2 
  128.          AutoSize        =   -1  'True
  129.          Caption         =   "Ship To:"
  130.          BeginProperty Font 
  131.             Name            =   "Tahoma"
  132.             Size            =   8.25
  133.             Charset         =   0
  134.             Weight          =   700
  135.             Underline       =   0   'False
  136.             Italic          =   0   'False
  137.             Strikethrough   =   0   'False
  138.          EndProperty
  139.          Height          =   195
  140.          Index           =   5
  141.          Left            =   60
  142.          TabIndex        =   35
  143.          Top             =   30
  144.          Width           =   660
  145.       End
  146.    End
  147.    Begin VB.PictureBox Picture2 
  148.       Height          =   1785
  149.       Index           =   1
  150.       Left            =   105
  151.       ScaleHeight     =   115
  152.       ScaleMode       =   3  'Pixel
  153.       ScaleWidth      =   256
  154.       TabIndex        =   20
  155.       Top             =   75
  156.       Width           =   3900
  157.       Begin VB.CommandButton cmdCustomerID 
  158.          Caption         =   "..."
  159.          Height          =   255
  160.          Left            =   1905
  161.          TabIndex        =   36
  162.          TabStop         =   0   'False
  163.          Top             =   90
  164.          Width           =   345
  165.       End
  166.       Begin VB.TextBox txtCustomerID 
  167.          Height          =   315
  168.          Left            =   765
  169.          TabIndex        =   1
  170.          Top             =   60
  171.          Width           =   1515
  172.       End
  173.       Begin VB.TextBox txtCustInfo 
  174.          BorderStyle     =   0  'None
  175.          Height          =   240
  176.          Index           =   0
  177.          Left            =   780
  178.          Locked          =   -1  'True
  179.          TabIndex        =   27
  180.          Top             =   420
  181.          Width           =   3000
  182.       End
  183.       Begin VB.TextBox txtCustInfo 
  184.          BorderStyle     =   0  'None
  185.          Height          =   405
  186.          Index           =   1
  187.          Left            =   780
  188.          Locked          =   -1  'True
  189.          MultiLine       =   -1  'True
  190.          TabIndex        =   26
  191.          Top             =   705
  192.          Width           =   3000
  193.       End
  194.       Begin VB.TextBox txtCustInfo 
  195.          BorderStyle     =   0  'None
  196.          Height          =   240
  197.          Index           =   4
  198.          Left            =   2805
  199.          Locked          =   -1  'True
  200.          TabIndex        =   25
  201.          Top             =   1155
  202.          Width           =   975
  203.       End
  204.       Begin VB.TextBox txtCustInfo 
  205.          BorderStyle     =   0  'None
  206.          Height          =   240
  207.          Index           =   5
  208.          Left            =   1650
  209.          Locked          =   -1  'True
  210.          TabIndex        =   24
  211.          Top             =   1440
  212.          Width           =   2130
  213.       End
  214.       Begin VB.TextBox txtCustInfo 
  215.          BorderStyle     =   0  'None
  216.          Height          =   240
  217.          Index           =   2
  218.          Left            =   780
  219.          Locked          =   -1  'True
  220.          TabIndex        =   22
  221.          Top             =   1155
  222.          Width           =   975
  223.       End
  224.       Begin VB.TextBox txtCustInfo 
  225.          BorderStyle     =   0  'None
  226.          Height          =   240
  227.          Index           =   3
  228.          Left            =   1800
  229.          Locked          =   -1  'True
  230.          TabIndex        =   21
  231.          Top             =   1155
  232.          Width           =   975
  233.       End
  234.       Begin VB.Label Label2 
  235.          AutoSize        =   -1  'True
  236.          Caption         =   "Bill To:"
  237.          BeginProperty Font 
  238.             Name            =   "Tahoma"
  239.             Size            =   8.25
  240.             Charset         =   0
  241.             Weight          =   700
  242.             Underline       =   0   'False
  243.             Italic          =   0   'False
  244.             Strikethrough   =   0   'False
  245.          EndProperty
  246.          Height          =   195
  247.          Index           =   6
  248.          Left            =   75
  249.          TabIndex        =   23
  250.          Top             =   90
  251.          Width           =   540
  252.       End
  253.    End
  254.    Begin VB.TextBox txtDate 
  255.       Height          =   315
  256.       Index           =   8
  257.       Left            =   6660
  258.       TabIndex        =   6
  259.       Top             =   2250
  260.       Width           =   1305
  261.    End
  262.    Begin VB.TextBox txtDate 
  263.       Height          =   315
  264.       Index           =   7
  265.       Left            =   3960
  266.       TabIndex        =   5
  267.       Top             =   2250
  268.       Width           =   1200
  269.    End
  270.    Begin VB.TextBox txtDate 
  271.       Height          =   315
  272.       Index           =   6
  273.       Left            =   1215
  274.       TabIndex        =   4
  275.       Top             =   2250
  276.       Width           =   1200
  277.    End
  278.    Begin VB.PictureBox Picture1 
  279.       Height          =   945
  280.       Left            =   5640
  281.       ScaleHeight     =   885
  282.       ScaleWidth      =   2310
  283.       TabIndex        =   11
  284.       Top             =   4470
  285.       Width           =   2370
  286.       Begin VB.TextBox txtFreight 
  287.          BorderStyle     =   0  'None
  288.          Height          =   240
  289.          Left            =   990
  290.          TabIndex        =   40
  291.          Top             =   330
  292.          Visible         =   0   'False
  293.          Width           =   1290
  294.       End
  295.       Begin VB.Label lblFreight 
  296.          Alignment       =   1  'Right Justify
  297.          BackColor       =   &H80000005&
  298.          ForeColor       =   &H80000007&
  299.          Height          =   240
  300.          Left            =   990
  301.          TabIndex        =   39
  302.          Top             =   330
  303.          Width           =   1290
  304.       End
  305.       Begin VB.Label lblTotal 
  306.          Alignment       =   1  'Right Justify
  307.          BackColor       =   &H80000005&
  308.          ForeColor       =   &H80000007&
  309.          Height          =   240
  310.          Left            =   990
  311.          TabIndex        =   38
  312.          Top             =   600
  313.          Width           =   1290
  314.       End
  315.       Begin VB.Label lblSubTotal 
  316.          Alignment       =   1  'Right Justify
  317.          BackColor       =   &H80000005&
  318.          ForeColor       =   &H80000007&
  319.          Height          =   240
  320.          Left            =   990
  321.          TabIndex        =   37
  322.          Top             =   60
  323.          Width           =   1290
  324.       End
  325.       Begin VB.Label Label1 
  326.          AutoSize        =   -1  'True
  327.          Caption         =   "Total:"
  328.          BeginProperty Font 
  329.             Name            =   "Tahoma"
  330.             Size            =   8.25
  331.             Charset         =   0
  332.             Weight          =   700
  333.             Underline       =   0   'False
  334.             Italic          =   0   'False
  335.             Strikethrough   =   0   'False
  336.          EndProperty
  337.          Height          =   195
  338.          Index           =   3
  339.          Left            =   135
  340.          TabIndex        =   14
  341.          Top             =   615
  342.          Width           =   480
  343.       End
  344.       Begin VB.Label Label1 
  345.          AutoSize        =   -1  'True
  346.          Caption         =   "Freight:"
  347.          BeginProperty Font 
  348.             Name            =   "Tahoma"
  349.             Size            =   8.25
  350.             Charset         =   0
  351.             Weight          =   700
  352.             Underline       =   0   'False
  353.             Italic          =   0   'False
  354.             Strikethrough   =   0   'False
  355.          EndProperty
  356.          Height          =   195
  357.          Index           =   2
  358.          Left            =   135
  359.          TabIndex        =   13
  360.          Top             =   345
  361.          Width           =   645
  362.       End
  363.       Begin VB.Label Label1 
  364.          AutoSize        =   -1  'True
  365.          Caption         =   "SubTotal:"
  366.          BeginProperty Font 
  367.             Name            =   "Tahoma"
  368.             Size            =   8.25
  369.             Charset         =   0
  370.             Weight          =   700
  371.             Underline       =   0   'False
  372.             Italic          =   0   'False
  373.             Strikethrough   =   0   'False
  374.          EndProperty
  375.          Height          =   195
  376.          Index           =   1
  377.          Left            =   135
  378.          TabIndex        =   12
  379.          Top             =   75
  380.          Width           =   795
  381.       End
  382.    End
  383.    Begin JSGridEX.GridEX gexDetails 
  384.       Height          =   1695
  385.       Left            =   90
  386.       TabIndex        =   7
  387.       Top             =   2655
  388.       Width           =   7905
  389.       _ExtentX        =   13944
  390.       _ExtentY        =   2990
  391.       MethodHoldFields=   -1  'True
  392.       SelectionStyle  =   1
  393.       DatabaseName    =   "C:\Advanced Sample\Nwind.mdb"
  394.       AutomaticArrange=   0   'False
  395.       AllowDelete     =   -1  'True
  396.       GroupByBoxVisible=   0   'False
  397.       NewRowPos       =   1
  398.       RowHeaders      =   -1  'True
  399.       ColumnCount     =   7
  400.       ColCaption1     =   "OrderID"
  401.       ColDataField1   =   "OrderID"
  402.       ColKey1         =   "OrderID"
  403.       ColVisible1     =   0   'False
  404.       ColSortType1    =   2
  405.       ColTextAlignment2=   2
  406.       ColCaption2     =   "Product ID"
  407.       ColDataField2   =   "ProductID"
  408.       ColKey2         =   "ProductID"
  409.       ColWidth2       =   1095
  410.       ColSortType2    =   2
  411.       ColFormat3      =   "Currency"
  412.       ColTextAlignment3=   2
  413.       ColCaption3     =   "Unit Price"
  414.       ColDataField3   =   "UnitPrice"
  415.       ColKey3         =   "UnitPrice"
  416.       ColPosition3    =   4
  417.       ColWidth3       =   900
  418.       ColSortType3    =   2
  419.       ColTextAlignment4=   2
  420.       ColCaption4     =   "Quantity"
  421.       ColDataField4   =   "Quantity"
  422.       ColKey4         =   "Quantity"
  423.       ColPosition4    =   5
  424.       ColWidth4       =   810
  425.       ColSortType4    =   2
  426.       ColTextAlignment5=   2
  427.       ColCaption5     =   "Discount"
  428.       ColDataField5   =   "Discount"
  429.       ColKey5         =   "Discount"
  430.       ColPosition5    =   6
  431.       ColWidth5       =   840
  432.       ColSortType5    =   2
  433.       ColCaption6     =   "Product"
  434.       ColDataField6   =   "ProductName"
  435.       ColKey6         =   "ProductName"
  436.       ColPosition6    =   3
  437.       ColWidth6       =   2400
  438.       ColEditType6    =   0
  439.       ColFormat7      =   "Currency"
  440.       ColTextAlignment7=   2
  441.       ColCaption7     =   "Price"
  442.       ColDataField7   =   "Price"
  443.       ColKey7         =   "Price"
  444.       ColWidth7       =   1200
  445.       ColEditType7    =   0
  446.       HeaderFontBold  =   -1  'True
  447.       HeaderFontWeight=   700
  448.       AllowAddNew     =   -1  'True
  449.       ColumnHeaderHeight=   285
  450.    End
  451.    Begin VB.Label Label2 
  452.       AutoSize        =   -1  'True
  453.       Caption         =   "Ship Via:"
  454.       Height          =   195
  455.       Index           =   4
  456.       Left            =   4530
  457.       TabIndex        =   19
  458.       Top             =   1965
  459.       Width           =   615
  460.    End
  461.    Begin VB.Label Label2 
  462.       AutoSize        =   -1  'True
  463.       Caption         =   "Salesperson:"
  464.       Height          =   195
  465.       Index           =   3
  466.       Left            =   120
  467.       TabIndex        =   18
  468.       Top             =   1995
  469.       Width           =   930
  470.    End
  471.    Begin VB.Label Label2 
  472.       AutoSize        =   -1  'True
  473.       Caption         =   "Shipped Date:"
  474.       Height          =   195
  475.       Index           =   2
  476.       Left            =   5385
  477.       TabIndex        =   17
  478.       Top             =   2310
  479.       Width           =   1020
  480.    End
  481.    Begin VB.Label Label2 
  482.       AutoSize        =   -1  'True
  483.       Caption         =   "Required Date:"
  484.       Height          =   195
  485.       Index           =   1
  486.       Left            =   2640
  487.       TabIndex        =   16
  488.       Top             =   2310
  489.       Width           =   1095
  490.    End
  491.    Begin VB.Label Label2 
  492.       AutoSize        =   -1  'True
  493.       Caption         =   "Order Date:"
  494.       Height          =   195
  495.       Index           =   0
  496.       Left            =   120
  497.       TabIndex        =   15
  498.       Top             =   2310
  499.       Width           =   870
  500.    End
  501.    Begin VB.Label lblOrderNo 
  502.       BackStyle       =   0  'Transparent
  503.       Caption         =   " N/A"
  504.       BeginProperty Font 
  505.          Name            =   "Tahoma"
  506.          Size            =   9.75
  507.          Charset         =   0
  508.          Weight          =   700
  509.          Underline       =   0   'False
  510.          Italic          =   0   'False
  511.          Strikethrough   =   0   'False
  512.       EndProperty
  513.       Height          =   240
  514.       Left            =   7350
  515.       TabIndex        =   10
  516.       Top             =   90
  517.       Width           =   600
  518.    End
  519.    Begin VB.Label Label1 
  520.       BackStyle       =   0  'Transparent
  521.       Caption         =   "ORDER #"
  522.       BeginProperty Font 
  523.          Name            =   "Tahoma"
  524.          Size            =   8.25
  525.          Charset         =   0
  526.          Weight          =   700
  527.          Underline       =   0   'False
  528.          Italic          =   0   'False
  529.          Strikethrough   =   0   'False
  530.       EndProperty
  531.       Height          =   195
  532.       Index           =   0
  533.       Left            =   6420
  534.       TabIndex        =   0
  535.       Top             =   120
  536.       Width           =   750
  537.    End
  538.    Begin VB.Image Image1 
  539.       Height          =   240
  540.       Index           =   3
  541.       Left            =   6075
  542.       Picture         =   "frmOrders.frx":014A
  543.       Stretch         =   -1  'True
  544.       Top             =   90
  545.       Width           =   240
  546.    End
  547.    Begin VB.Shape Shape1 
  548.       BackStyle       =   1  'Opaque
  549.       Height          =   375
  550.       Left            =   5985
  551.       Top             =   30
  552.       Width           =   1995
  553.    End
  554. Attribute VB_Name = "frmOrders"
  555. Attribute VB_GlobalNameSpace = False
  556. Attribute VB_Creatable = False
  557. Attribute VB_PredeclaredId = True
  558. Attribute VB_Exposed = False
  559. Option Explicit
  560. Dim m_db As Database
  561. Dim mrstOrders As Recordset
  562. Dim mrstCustomers As Recordset
  563. Dim mrstProducts As Recordset
  564. Dim mbIsNew As Boolean
  565. Dim mvarBookmark As Variant
  566. Const fldShipTo = 0
  567. Const fldShipAddress = 1
  568. Const fldShipCity = 2
  569. Const fldShipRegion = 3
  570. Const fldShipPostalCode = 4
  571. Const fldShipCountry = 5
  572. Const fldOrderDate = 6
  573. Const fldRequiredDate = 7
  574. Const fldShippedDate = 8
  575. Const fldEmployeeID = 9
  576. Const fldShipVia = 10
  577. Const fldFreight = 11
  578. Const fldCustomerID = 12
  579. Const fldCustName = 0
  580. Const fldCustAddress = 1
  581. Const fldCustCity = 2
  582. Const fldCustRegion = 3
  583. Const fldCustPostalCode = 4
  584. Const fldCustCountry = 5
  585. Dim m_DataChanged(0 To 12) As Boolean
  586. Public Key As String
  587. Public Sub SeeOrder(rst As Recordset)
  588. Dim rstTemp As Recordset
  589. Dim dbtemp As Database
  590. On Error Resume Next
  591.     Caption = "Orders - " & rst![OrderID]
  592.     lblOrderNo = rst![OrderID]
  593.     txtShip(0) = rst![ShipName]
  594.     txtShip(1) = rst![ShipAddress]
  595.     txtShip(2) = rst![ShipCity]
  596.     txtShip(3) = rst![ShipRegion]
  597.     txtShip(4) = rst![ShipPostalCode]
  598.     txtShip(5) = rst![ShipCountry]
  599.     Set dbtemp = OpenDatabase(gexDetails.DatabaseName)
  600.     Set rstTemp = dbtemp.OpenRecordset("Employees", dbOpenTable)
  601.     rstTemp.Index = "PrimaryKey"
  602.     rstTemp.Seek "=", rst![EmployeeID]
  603.     rstTemp.Close
  604.     Set rstTemp = dbtemp.OpenRecordset("Shippers", dbOpenTable)
  605.     rstTemp.Index = "PrimaryKey"
  606.     rstTemp.Seek "=", rst![ShipVia]
  607.     rstTemp.Close
  608.     Set rstTemp = dbtemp.OpenRecordset("Customers", dbOpenTable)
  609.     rstTemp.Index = "PrimaryKey"
  610.     rstTemp.Seek "=", rst![CustomerID]
  611.     If Not rstTemp.NoMatch Then
  612.         txtShip(11) = rstTemp![CompanyName]
  613.         txtShip(10) = rstTemp![Address]
  614.         txtShip(9) = rstTemp![City]
  615.         txtShip(8) = rstTemp![Region]
  616.         txtShip(7) = rstTemp![PostalCode]
  617.         txtShip(6) = rstTemp![Country]
  618.     End If
  619.     gexDetails.RecordSource = "SELECT [Order Details].*, Products.ProductName, ([Order Details]![UnitPrice]*[Order Details]![Quantity])*(1-[Order Details]![Discount]) AS Price FROM Products INNER JOIN [Order Details] ON Products.ProductID = [Order Details].ProductID WHERE [Order Details].OrderID=" & rst![OrderID]
  620.     gexDetails.HoldFields
  621.     gexDetails.Rebind
  622.     CalculateTotals rst![Freight]
  623.     Show
  624. End Sub
  625. Private Sub CalculateTotals(Freight As Currency)
  626. Dim rst As Recordset
  627. Dim amount As Currency
  628.     Set rst = gexDetails.Recordset
  629.     On Error Resume Next
  630.     rst.MoveFirst
  631.     Do Until rst.EOF
  632.         amount = amount + rst![Price]
  633.         rst.MoveNext
  634.     Loop
  635.     lblSubTotal = Format(amount, "Currency")
  636.     lblFreight = Format(Freight, "Currency")
  637.     lblTotal = Format(amount + Freight, "Currency")
  638. End Sub
  639. Private Sub cboEmployee_Click()
  640.     m_DataChanged(fldEmployeeID) = True
  641. End Sub
  642. Private Sub cboEmployee_Change()
  643.     m_DataChanged(fldEmployeeID) = True
  644. End Sub
  645. Private Sub cboShippers_Click()
  646.     m_DataChanged(fldShipVia) = True
  647. End Sub
  648. Private Sub cboShippers_Change()
  649.     m_DataChanged(fldShipVia) = True
  650. End Sub
  651. Private Sub cmdCancel_Click()
  652.     If mbIsNew And Not IsNull(mvarBookmark) Then
  653.         mrstOrders.Delete
  654.     End If
  655.     Unload Me
  656. End Sub
  657. Private Sub cmdCustomerID_Click()
  658. Dim varCustID As Variant
  659.     varCustID = frmList.ChooseCustomer(m_db.Name, txtCustomerID)
  660.     If Not IsNull(varCustID) Then
  661.         txtCustomerID = varCustID
  662.         txtCustomerID.SelStart = 0
  663.         txtCustomerID.SelLength = Len(txtCustomerID)
  664.         
  665.     End If
  666.     txtCustomerID.SetFocus
  667. End Sub
  668. Private Sub cmdOK_Click()
  669. On Error GoTo EH_cmdOK
  670.     If ActiveControl Is txtFreight Then
  671.         txtFreight_LostFocus
  672.     ElseIf ActiveControl Is gexDetails Then
  673.         gexDetails.Update
  674.     End If
  675.     If Not SaveOrder Then Exit Sub
  676.     If mbIsNew Then
  677.         frmMain.OnRecordUpdate CatalogOrders, Null
  678.     Else
  679.         frmMain.OnRecordUpdate CatalogOrders, mvarBookmark
  680.     End If
  681.     Unload Me
  682.     Exit Sub
  683. EH_cmdOK:
  684.     MsgBox Err.Description
  685. End Sub
  686. Private Sub Form_Unload(Cancel As Integer)
  687.     frmMain.UnloadForm Key
  688. End Sub
  689. Private Sub gexDetails_AfterColUpdate(ByVal ColIndex As Integer)
  690. On Error Resume Next
  691. Dim curUnitPrice As Currency
  692. Dim sngQuantity As Single
  693. Dim sngDiscount As Single
  694. Dim colQuantity As Column
  695.     Set colQuantity = gexDetails.Columns("Quantity")
  696.     If Not colQuantity.DataChanged Then
  697.         gexDetails.Value(colQuantity.Index) = 1
  698.     End If
  699.     Select Case ColIndex
  700.         Case 2
  701.             mrstProducts.Index = "PrimaryKey"
  702.             mrstProducts.Seek "=", gexDetails.Value(2)
  703.             If mrstProducts.NoMatch Then
  704.                 gexDetails.Value(6) = ""
  705.             Else
  706.                 gexDetails.Value(6) = mrstProducts![ProductName]
  707.                 gexDetails.Value(3) = mrstProducts![UnitPrice]
  708.                 gexDetails_AfterColUpdate 3
  709.             End If
  710.         Case 3, 4, 5
  711.             curUnitPrice = CCur(gexDetails.Value(3))
  712.             sngQuantity = CSng(gexDetails.Value(4))
  713.             sngDiscount = CSng(gexDetails.Value(5))
  714.             gexDetails.Value(7) = curUnitPrice * sngQuantity * (1 - sngDiscount)
  715.     End Select
  716. End Sub
  717. Private Sub gexDetails_AfterDelete()
  718.     gexDetails_AfterUpdate
  719. End Sub
  720. Private Sub gexDetails_AfterUpdate()
  721.     If lblFreight.Caption = "" Then
  722.         CalculateTotals 0
  723.     Else
  724.         CalculateTotals CCur(lblFreight.Caption)
  725.     End If
  726. End Sub
  727. Private Sub gexDetails_BeforeUpdate(Cancel As Boolean)
  728.     If IsNull(mvarBookmark) Then
  729.         If Len(txtCustomerID.Text) = 0 Then
  730.             MsgBox "Select a customer to bill to before entering order details info.", vbInformation
  731.             gexDetails.DataChanged = False
  732.             txtCustomerID.SetFocus
  733.             Cancel = True
  734.             Exit Sub
  735.         Else
  736.             If Not SaveOrder Then
  737.                 Cancel = True
  738.             End If
  739.         End If
  740.     End If
  741.     If gexDetails.Value(1) = "" Then
  742.         gexDetails.Value(1) = mrstOrders![OrderID]
  743.     End If
  744.     gexDetails.Columns(6).DataChanged = False
  745.     gexDetails.Columns(7).DataChanged = False
  746. End Sub
  747. Private Sub gexDetails_ColumnHeaderClick(Column As JSGridEX.Column)
  748.     gexDetails.SortKeys.Clear
  749.     gexDetails.SortKeys.Add Column.Index, jgexSortAscending
  750. End Sub
  751. Private Sub lblFreight_Click()
  752.     txtFreight.Text = lblFreight.Caption
  753.     txtFreight.SelStart = 0
  754.     txtFreight.SelLength = Len(txtFreight)
  755.     txtFreight.Visible = True
  756.     txtFreight.SetFocus
  757. End Sub
  758. Private Sub txtCustomerID_Change()
  759.     SearchCustomer
  760.     m_DataChanged(fldCustomerID) = True
  761. End Sub
  762. Private Sub SearchCustomer()
  763. On Error Resume Next
  764. Dim i As Integer
  765.     mrstCustomers.Index = "PrimaryKey"
  766.     mrstCustomers.Seek "=", txtCustomerID
  767.     If mrstCustomers.NoMatch Then
  768.         For i = fldCustName To fldCustCountry
  769.             txtCustInfo(i).Text = ""
  770.         Next
  771.     Else
  772.         txtCustInfo(fldCustName) = mrstCustomers![CompanyName]
  773.         txtCustInfo(fldCustAddress) = mrstCustomers![Address]
  774.         txtCustInfo(fldCustCity) = mrstCustomers![City]
  775.         txtCustInfo(fldCustRegion) = mrstCustomers![Region]
  776.         txtCustInfo(fldCustPostalCode) = mrstCustomers![PostalCode]
  777.         txtCustInfo(fldCustCountry) = mrstCustomers![Country]
  778.         If Not m_DataChanged(fldShipTo) Then txtShip(fldShipTo).Text = mrstCustomers![ContactName]
  779.         If Not m_DataChanged(fldShipAddress) Then txtShip(fldShipAddress).Text = mrstCustomers![Address]
  780.         If Not m_DataChanged(fldShipCity) Then txtShip(fldShipCity).Text = mrstCustomers![City]
  781.         If Not m_DataChanged(fldShipRegion) Then txtShip(fldShipRegion).Text = mrstCustomers![Region]
  782.         If Not m_DataChanged(fldShipPostalCode) Then txtShip(fldShipPostalCode).Text = mrstCustomers![PostalCode]
  783.         If Not m_DataChanged(fldShipCountry) Then txtShip(fldShipCountry).Text = mrstCustomers![Country]
  784.     End If
  785. End Sub
  786. Public Sub EditRecord(db As Database, rs As Recordset)
  787. Dim i As Long
  788. Dim lngID As Long
  789. On Error Resume Next
  790.     Set m_db = db
  791.     Set mrstCustomers = m_db.OpenRecordset("Customers", dbOpenTable)
  792.     Set mrstProducts = m_db.OpenRecordset("Products", dbOpenTable)
  793.     Set mrstOrders = rs.Clone
  794.     mvarBookmark = rs.Bookmark
  795.     mrstOrders.Bookmark = mvarBookmark
  796.     FillEmployeeList
  797.     FillShippersList
  798.     txtCustomerID.Text = mrstOrders![CustomerID]
  799.     txtShip(fldShipTo).Text = mrstOrders![ShipName]
  800.     txtShip(fldShipAddress).Text = mrstOrders![ShipAddress]
  801.     txtShip(fldShipCity).Text = mrstOrders![ShipCity]
  802.     txtShip(fldShipRegion).Text = mrstOrders![ShipRegion]
  803.     txtShip(fldShipPostalCode).Text = mrstOrders![ShipPostalCode]
  804.     txtShip(fldShipCountry).Text = mrstOrders![ShipCountry]
  805.     txtDate(fldOrderDate) = Format(mrstOrders![OrderDate], "Medium Date")
  806.     txtDate(fldRequiredDate) = Format(mrstOrders![RequiredDate], "Medium Date")
  807.     txtDate(fldShippedDate) = Format(mrstOrders![ShippedDate], "Medium Date")
  808.     If Not IsNull(mrstOrders![EmployeeID]) Then
  809.         lngID = mrstOrders![EmployeeID]
  810.     End If
  811.     For i = 0 To cboEmployee.ListCount - 1
  812.         If cboEmployee.ItemData(i) = lngID Then
  813.             cboEmployee.ListIndex = i
  814.             Exit For
  815.         End If
  816.     Next
  817.     If Not IsNull(mrstOrders![ShipVia]) Then
  818.         lngID = mrstOrders![ShipVia]
  819.     Else
  820.         lngID = 0
  821.     End If
  822.     For i = 0 To cboShippers.ListCount - 1
  823.         If cboShippers.ItemData(i) = lngID Then
  824.             cboShippers.ListIndex = i
  825.             Exit For
  826.         End If
  827.     Next
  828.     lblOrderNo.Caption = mrstOrders![OrderID]
  829.     Caption = "Orders - Order # " & mrstOrders![OrderID]
  830.     For i = 0 To UBound(m_DataChanged)
  831.         m_DataChanged(i) = False
  832.     Next
  833.     gexDetails.DatabaseName = m_db.Name
  834.     gexDetails.RecordSource = "SELECT [Order Details].*, Products.ProductName, ([Order Details]![UnitPrice]*[Order Details]![Quantity])*(1-[Order Details]![Discount]) AS Price FROM Products INNER JOIN [Order Details] ON Products.ProductID = [Order Details].ProductID WHERE [Order Details].OrderID=" & mrstOrders![OrderID]
  835.     gexDetails.HoldFields
  836.     gexDetails.Rebind
  837.     If IsNull(mrstOrders![Freight]) Then
  838.         Call CalculateTotals(0)
  839.     Else
  840.         Call CalculateTotals(mrstOrders![Freight])
  841.     End If
  842.     Me.Show
  843. End Sub
  844. Public Sub NewRecord(db As Database, rs As Recordset)
  845. Dim i As Long
  846. Dim lngID As Long
  847. On Error Resume Next
  848.     Set m_db = db
  849.     Set mrstCustomers = m_db.OpenRecordset("Customers", dbOpenTable)
  850.     Set mrstProducts = m_db.OpenRecordset("Products", dbOpenTable)
  851.     Set mrstOrders = rs.Clone
  852.     mbIsNew = True
  853.     mvarBookmark = Null
  854.     FillEmployeeList
  855.     FillShippersList
  856.     txtDate(fldOrderDate) = Format(Date, "Medium Date")
  857.     txtDate(fldShippedDate) = Format(Date, "Medium Date")
  858.     txtDate(fldRequiredDate) = Format(Date, "Medium Date")
  859.     Caption = "Orders - New Order"
  860.     For i = 0 To UBound(m_DataChanged)
  861.         m_DataChanged(i) = False
  862.     Next
  863.     gexDetails.DatabaseName = m_db.Name
  864.     gexDetails.RecordSource = "SELECT [Order Details].*, Products.ProductName, ([Order Details]![UnitPrice]*[Order Details]![Quantity])*(1-[Order Details]![Discount]) AS Price FROM Products INNER JOIN [Order Details] ON Products.ProductID = [Order Details].ProductID WHERE [Order Details].OrderID=0"
  865.     gexDetails.HoldFields
  866.     gexDetails.Rebind
  867.     Call CalculateTotals(0)
  868.     Me.Show
  869. End Sub
  870. Private Sub FillEmployeeList()
  871. Dim rsTemp As Recordset
  872.     Set rsTemp = m_db.OpenRecordset("SELECT Employees.EmployeeID, Employees.FirstName & ' ' & Employees.LastName AS Name From Employees", dbOpenSnapshot)
  873.     cboEmployee.Clear
  874.     cboEmployee.AddItem ""
  875.     Do Until rsTemp.EOF
  876.         cboEmployee.AddItem rsTemp![Name]
  877.         cboEmployee.ItemData(cboEmployee.NewIndex) = rsTemp![EmployeeID]
  878.         rsTemp.MoveNext
  879.     Loop
  880. End Sub
  881. Private Sub FillShippersList()
  882. Dim rsTemp As Recordset
  883.     Set rsTemp = m_db.OpenRecordset("SELECT * From Shippers", dbOpenSnapshot)
  884.     cboShippers.Clear
  885.     cboShippers.AddItem ""
  886.     Do Until rsTemp.EOF
  887.         cboShippers.AddItem rsTemp![CompanyName]
  888.         cboShippers.ItemData(cboShippers.NewIndex) = rsTemp![ShipperID]
  889.         rsTemp.MoveNext
  890.     Loop
  891. End Sub
  892. Private Sub txtDate_Change(Index As Integer)
  893.     m_DataChanged(Index) = True
  894. End Sub
  895. Private Sub txtFreight_Change()
  896.     m_DataChanged(fldFreight) = True
  897. End Sub
  898. Private Sub txtFreight_LostFocus()
  899. Dim cTemp As Currency
  900. On Error Resume Next
  901.     cTemp = CCur(txtFreight)
  902.     If Err = 0 Then
  903.         CalculateTotals (cTemp)
  904.     End If
  905.     txtFreight.Visible = False
  906. End Sub
  907. Private Sub txtShip_Change(Index As Integer)
  908.     m_DataChanged(Index) = True
  909. End Sub
  910. Private Function SaveOrder() As Boolean
  911. On Error GoTo EH_SaveOrder
  912. Dim curTemp As Currency
  913.     If IsDirty Then
  914.         If IsNull(mvarBookmark) Then
  915.             mrstOrders.AddNew
  916.         Else
  917.             mrstOrders.Bookmark = mvarBookmark
  918.             mrstOrders.Edit
  919.         End If
  920.         If m_DataChanged(fldCustomerID) Then mrstOrders![CustomerID] = txtCustomerID
  921.         If m_DataChanged(fldShipTo) Then mrstOrders![ShipName] = txtShip(fldShipTo)
  922.         If m_DataChanged(fldShipAddress) Then mrstOrders![ShipAddress] = txtShip(fldShipAddress)
  923.         If m_DataChanged(fldShipRegion) Then mrstOrders![ShipRegion] = txtShip(fldShipRegion)
  924.         If m_DataChanged(fldShipCity) Then mrstOrders![ShipCity] = txtShip(fldShipCity)
  925.         If m_DataChanged(fldShipPostalCode) Then mrstOrders![ShipPostalCode] = txtShip(fldShipPostalCode)
  926.         If m_DataChanged(fldShipCountry) Then mrstOrders![ShipCountry] = txtShip(fldShipCountry)
  927.         If m_DataChanged(fldOrderDate) Then mrstOrders![OrderDate] = TextToNull(txtDate(fldOrderDate))
  928.         If m_DataChanged(fldRequiredDate) Then mrstOrders![RequiredDate] = TextToNull(txtDate(fldRequiredDate))
  929.         If m_DataChanged(fldShippedDate) Then mrstOrders![ShippedDate] = TextToNull(txtDate(fldShippedDate))
  930.         If m_DataChanged(fldFreight) Then
  931.             On Error Resume Next
  932.             curTemp = CCur(lblFreight)
  933.             On Error GoTo EH_SaveOrder
  934.             mrstOrders![Freight] = curTemp
  935.         End If
  936.         If m_DataChanged(fldEmployeeID) Then
  937.             If cboEmployee.Text = "" Then
  938.                 mrstOrders![EmployeeID] = Null
  939.             Else
  940.                 mrstOrders![EmployeeID] = cboEmployee.ItemData(cboEmployee.ListIndex)
  941.             End If
  942.         End If
  943.         If m_DataChanged(fldShipVia) Then
  944.             If cboShippers.Text = "" Then
  945.                 mrstOrders![ShipVia] = Null
  946.             Else
  947.                 mrstOrders![ShipVia] = cboShippers.ItemData(cboShippers.ListIndex)
  948.             End If
  949.         End If
  950.         Dim vTemp As Variant
  951.         mrstOrders.Update
  952.         If IsNull(mvarBookmark) Then
  953.             mvarBookmark = mrstOrders.LastModified
  954.             mrstOrders.Bookmark = mvarBookmark
  955.         End If
  956.         
  957.         lblOrderNo.Caption = mrstOrders![OrderID]
  958.         Caption = "Orders - Order # " & mrstOrders![OrderID]
  959.     End If
  960.     SaveOrder = True
  961.     Exit Function
  962. EH_SaveOrder:
  963.     MsgBox Err.Description, vbExclamation
  964. End Function
  965. Private Function IsDirty() As Boolean
  966. Dim i As Integer
  967.     For i = 0 To UBound(m_DataChanged)
  968.         If m_DataChanged(i) Then
  969.             IsDirty = True
  970.             Exit Function
  971.         End If
  972.     Next
  973. End Function
  974.